package com.fruit.controller.app.goods;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fruit.controller.base.BaseController;
import com.fruit.pojo.common.Page;
import com.fruit.service.goodspackage.GoodsPackageManager;
import com.fruit.util.ResultInfo;
import com.fruit.util.ResultUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 产品套餐相关
 * 
 * @author Administrator
 * @version 2018.02.02 12:40
 */
@Slf4j
@Controller
@RequestMapping(value = "/app/goodspackage")
public class GoodsPackageController extends BaseController {
	@Autowired
	private GoodsPackageManager goodsPackageService;

	/**
	 * 产品套餐列表
	 * 
	 * @param page
	 *            分页
	 * @param request
	 *            请求
	 * @param session
	 *            session
	 * @return Map<String, Object>
	 */
	@RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
	@ResponseBody
	public Map<String, Object> list(Page page, HttpServletRequest request, HttpSession session) {
		log.info("【产品套餐列表】---【开始】--");
		Map<String, Object> result = new HashMap<String, Object>();
		try {
			if (page == null) {
				result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "param_error", "传入分页参数不能为空!"));
				return result;
			}
			log.info("【产品套餐列表】---【params】--page=" + page.getPage() + "showNumber=" + page.getShowNum());
			Map<String, Object> pam = new HashMap<String, Object>();
			pam.put("startNum", (page.getPage() - 1) * page.getShowNum());
			pam.put("pageNum", page.getShowNum());

			result = goodsPackageService.getRecords(pam);
			log.info("【产品套餐列表】---【操作成功】--");
		} catch (Exception e) {
			log.error("【产品套餐列表】---【异常】---{}", e);
			result.put("result", ResultUtil.initResult(ResultInfo.ERROR, "exception", "系统异常"));
		}
		log.info("【产品套餐列表】---【结束】--");
		return result;
	}
}
